<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Categoria extends CI_Controller {

    function __construct() {
        parent::__construct();
        /* cargo librerias necesarias */
        $this->load->helper('url');
        $this->load->database();
        $this->load->library('session');
        $this->load->model('category');
        $this->load->library('pagination');
        $ci = &get_instance();
        existeCiudad($ci);
    }


    function view($slug, $desde = 0, $order_by = 'precio') {
    
        $order_by = !isset($_POST["orden"]) ? "precio": $_POST["orden"];

        $this->load->library('pagination');
        $cat_select = $this->uri->segment(3);
        $opciones = array();
        $desde = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
        $opciones['per_page'] = 12;
        $opciones['base_url'] = base_url() . '/categoria/view/' . $cat_select;
        $opciones['total_rows'] = $this->category->contarCursoEnCategoria($this->uri->segment(3),$this->session->userdata('city'));
        $opciones['uri_segment'] = 4;
        $opciones['use_page_numbers'] = true;
        $opciones['full_tag_open'] = '<div class="pagination pagination-small pagination-centered"><ul>';
        $opciones['full_tag_close'] = '</ul></div>';
        $opciones['prev_link'] = '&lt;&lt;';
        $opciones['prev_tag_open'] = '<li>';
        $opciones['prev_tag_close'] = '</li>';
        $opciones['next_link'] = '&gt;&gt;';
        $opciones['next_tag_open'] = '<li>';
        $opciones['next_tag_close'] = '</li>';
        $opciones['cur_tag_open'] = '<li class="active"><a href="#">';
        $opciones['cur_tag_close'] = '</a></li>';
        $opciones['num_tag_open'] = '<li>';
        $opciones['num_tag_close'] = '</li>';
        $opciones['first_link'] = True;
        $opciones['last_link'] = true;
        $opciones['display_pages'] = true;

        $this->pagination->initialize($opciones);

        $data['lista'] = $this->category->getTodosCursos($opciones['per_page'], $desde, $order_by,$this->uri->segment(3),$this->session->userdata('city'));
    
        $data["categoria"] = $this->category->getCategoriaBySlug($this->uri->segment(3));
     
        $data['paginacion'] = $this->pagination->create_links();
        $data["order_by"] = $order_by;
        $this->load->helper("utilidades");
        $this->load->view('home/header.php');
        $this->load->view('home/categoria.php', $data);
        $this->load->view('home/footer.php');
    }


}

?>